package bf.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.CharBuffer;

public class FileAccess {

	public static String getFileAsString(String path) throws IOException {
		String file = null;
		FileReader fl = new FileReader(path);
		int c = 0;
		StringBuffer sb = new StringBuffer();
		while (c != -1) {
			c = fl.read();
			sb.append((char)c);
		}
		file = sb.toString();
		return file;
	}

	public static void escribirArchivo(String path, String data)
	throws IOException
	{
		  FileWriter fstream = new FileWriter(path);
		  BufferedWriter out = new BufferedWriter(fstream);
		  out.write(data);
		  //Close the output stream
		  out.close();
		
	}

	public static void appendArchivo(String path, String data)
	throws IOException
	{
		  File archivo = new File(path);
	   System.out.println("UTIL: Escribiendo en " + archivo.getAbsolutePath());
		  FileWriter fstream = new FileWriter(archivo,true);
		  BufferedWriter out = new BufferedWriter(fstream);
		  out.write(data);
		  //Close the output stream
		  out.close();    	
	}

}
